package com.springboot.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import com.springboot.mapper.VirtualWalletTransactionMapper;
import com.springboot.model.bo.BVirtualWalletBO;
import com.springboot.model.bo.VirtualWalletTransactionBO;
import com.springboot.model.po.VirtualWalletTransactionPO;
import com.springboot.service.VirtualWalletTransactionService;

@Service
public class VirtualWalletTransactionServiceImpl implements VirtualWalletTransactionService {
    @Autowired
    private  VirtualWalletTransactionMapper transactionMapper;
  
	@Override
	public int saveTransaction(VirtualWalletTransactionPO transaction) {
		return transactionMapper.saveTransaction(transaction);
	}

	@Override
	public List<VirtualWalletTransactionBO> listTransactionBywalletId(Integer walletId) {
		List<VirtualWalletTransactionPO> list = transactionMapper.listTransactionBywalletId(walletId);
		if(list == null || list.size() == 0) {
			return new ArrayList<VirtualWalletTransactionBO>();
		}else {
			List result = new ArrayList<VirtualWalletTransactionBO>();
			for(VirtualWalletTransactionPO vpo : list) {
				VirtualWalletTransactionBO vbo = new VirtualWalletTransactionBO();
				vbo.setAmount(vpo.getAmount());
				vbo.setCreateTime(vpo.getCreateTime());
				vbo.setFromWalletId(vpo.getFromWalletId());
				vbo.setToWalletId(vpo.getToWalletId());
				vbo.setStatus(vpo.getStatus());
				vbo.setTransactionId(vpo.getTransactionId());
				vbo.setWalletId(vpo.getWalletId());
	    		result.add(vbo);
			}
			return result;
		}
	}

}
